﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Prism.Commands;
using Prism.Mvvm;
using TestWpfPrism.Accessors;

namespace TestWpfPrism
{
    public class MainWindowViewModel : BindableBase
    {
        public MainWindowViewModel(IStoreAccessor storeAccessor)
        {
            this.storeAccessor = storeAccessor;
        }

        private readonly IStoreAccessor storeAccessor;

        public ObservableCollection<string> Customers { get; private set; } = new();

        private string _selectedCustomer = "";

        public string SelectedCustomer
        {
            get => _selectedCustomer;
            set
            {
                if (SetProperty<string>(ref _selectedCustomer, value))
                {
                    Debug.WriteLine(_selectedCustomer ?? "no customer selected");
                }
            }
        }

        private DelegateCommand? _commandLoad = null;
        public DelegateCommand CommandLoad => _commandLoad ??= new DelegateCommand(CommandLoadExecute);

        private void CommandLoadExecute()
        {
            Customers.Clear();
            IEnumerable<string> list = storeAccessor.GetAll();
            Customers.AddRange(list);
        }
    }
}